<?php
namespace app\admin\controller;
class Order extends  Base
{

    public function index() {
        // 获取列表数据
        $orders = model("Order")->getOrdersByStatus();

        return $this->fetch('', [
            'orders' => $orders,
        ]);
    }

    public function noapply() {
        // 获取列表数据
        $orders = model("Order")->getOrdersByStatus(2);

        return $this->fetch('', [
            'orders' => $orders,
        ]);
    }

    public function nosend() {
        // 获取列表数据
        $orders = model("Order")->getOrdersByStatus(1);

        return $this->fetch('', [
            'orders' => $orders,
        ]);
    }

    public function send() {
        // 获取列表数据
        $orders = model("Order")->getOrdersByStatus(3);

        return $this->fetch('', [
            'orders' => $orders,
        ]);
    }

    public function finish() {
        // 获取列表数据
        $orders = model("Order")->getOrdersByStatus(4);

        return $this->fetch('', [
            'orders' => $orders,
        ]);
    }

    public function detail($id) {
        // 获取列表数据
        $order = model("Order")->get($id);

        return $this->fetch('', [
            'order' => $order,
        ]);
    }

    public function delist() {
        // 获取列表数据
        $orders = model("Order")->getOrdersByStatus(-1);

        return $this->fetch('', [
            'orders' => $orders,
        ]);
    }


    public function orderstatus(){
        $data=input('get.');
        $order=model('Order')->get($data['id']);
        $dealstatus=model('Deal')->updateBuyCountById($order['deal_id'], $order['deal_count'],$data['type']);
        $orderstatus=model('Order')->save(['status'=>2],['id'=>$data['id']]);
        if($dealstatus&&$orderstatus) {
            $this->success('状态更新成功');
        }else {
            $this->error('状态更新失败');
        }
    }

}
